<?php
namespace app\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Log;

class StaffModel extends Model
{

    // 设置表名NAME="staff_master";
    // 设置表名
    const TABLE_NAME = "staff_master";

    protected $table = 'staff_master';

    protected $primaryKey = 'staff_id';

    protected $staffModel = self::TABLE_NAME;

    public $timestamps = false;

    public function readstaffMaster() // 查
    {
        $sql = 'SELECT * FROM staff_master where delete_flg = 0 ';
        return DB::select($sql);
        // return $this->all();
    }

    public function delstaff($staff_id) // 删
    {
        $sql = 'update staff_master set delete_flg = 1 where staff_id = ?';
        $param = [
            $staff_id
        ];
        $delflag = DB::update($sql, $param);
        return $delflag;
    }

    public function updstaff($data, $list, $arr) // 改
    {
        $staffMaster = $this->where($list, '=', $data);
        return $staffMaster->update($arr);
    }

    public function getstaff($staffId) // 改
    {
        $sql = 'SELECT * FROM staff_master where delete_flg = 0 and staff_id = ?';
        return DB::select($sql, $staffId);
    }

    public function addstaff($data) // 增
    {
        return $this->insert($data);
    }

    public function readCorpStaffMaster($corpId) // 查
    {
        $sql = 'SELECT * FROM staff_master where delete_flg = 0 and corp_id = ? ';
        $param = [
            $corpId
        ];
        return DB::select($sql, $param);
        // return $this->all();
    }

    public function getstaffName($staffname)
    {
        $sql = 'SELECT * FROM staff_master where delete_flg = 0 and staff_name = ? ';
        $param = [
            $staffname
        ];
        return DB::select($sql, $param);
    }
}
